package com.share.book.controller;

import java.util.List;
import java.util.Arrays;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.book.domain.Entry;
import com.share.book.service.IEntryService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.share.common.core.web.page.TableDataInfo;

/**
 * 文档列表Controller
 *
 * @author atguigu
 * @date 2025-10-13
 */
@Tag(name = "文档列表接口管理")
@RestController
@RequestMapping("/entry")
public class EntryController extends BaseController
{
    @Autowired
    private IEntryService entryService;

    /**
     * 查询文档列表列表
     */
    @Operation(summary = "查询文档列表列表")
    @RequiresPermissions("book:entry:list")
    @GetMapping("/list")
    public TableDataInfo list(Entry entry)
    {
        startPage();
        List<Entry> list = entryService.selectEntryList(entry);
        return getDataTable(list);
    }

    /**
     * 导出文档列表列表
     */
    @Operation(summary = "导出文档列表列表")
    @RequiresPermissions("book:entry:export")
    @Log(title = "文档列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Entry entry)
    {
        List<Entry> list = entryService.selectEntryList(entry);
        ExcelUtil<Entry> util = new ExcelUtil<Entry>(Entry.class);
        util.exportExcel(response, list, "文档列表数据");
    }

    /**
     * 获取文档列表详细信息
     */
    @Operation(summary = "获取文档列表详细信息")
    @RequiresPermissions("book:entry:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(entryService.getById(id));
    }

    /**
     * 新增文档列表
     */
    @Operation(summary = "新增文档列表")
    @RequiresPermissions("book:entry:add")
    @Log(title = "文档列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Entry entry)
    {
        return toAjax(entryService.save(entry));
    }

    /**
     * 修改文档列表
     */
    @Operation(summary = "修改文档列表")
    @RequiresPermissions("book:entry:edit")
    @Log(title = "文档列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Entry entry)
    {
        return toAjax(entryService.updateById(entry));
    }

    /**
     * 删除文档列表
     */
    @Operation(summary = "删除文档列表")
    @RequiresPermissions("book:entry:remove")
    @Log(title = "文档列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) throws Exception {
        return toAjax(entryService.deleteBatchByIds(Arrays.asList(ids)));
    }
}
